﻿<UserControl x:Class="Sidvall.UI.Wpf.Controls.SecurityControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters" 
    xmlns:Controls="clr-namespace:Sidvall.UI.Wpf.Controls"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:vms="clr-namespace:Sidvall.UI.ViewModels;assembly=Sidvall.UI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 
    d:DesignHeight="240" d:DesignWidth="600">

    <UserControl.Resources>
        <Converters:InverseBooleanConverter x:Key="InverseBooleanConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter2" Not="True" />
    </UserControl.Resources>

    <Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:SecurityControlViewModel}}">
        <Grid IsEnabled="{Binding IsBusy, Converter={StaticResource InverseBooleanConverter}}" >
            <TabControl x:Name="TabControl" BorderThickness="0" Padding="0">
                <TabItem Visibility="Collapsed">
                    <Grid>
                        <TextBlock Text="{Binding ResourceKeyManager.SecurityControlLogOffMessage}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </Grid>
                </TabItem>
                <TabItem Visibility="Collapsed">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlUserName}"/>
                                <TextBox x:Name="UserNameBox" Grid.Column="1" Text="{Binding UserName, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                         Height="30" Padding="5,0" />
                            </StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlPassword}"/>
                                <PasswordBox x:Name="PasswordBox" Grid.Column="1" VerticalContentAlignment="Center" Height="30" Padding="5,0" />
                            </StackPanel>
                            <Grid Margin="8">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <CheckBox Content="{Binding ResourceKeyManager.SecurityControlRememberMe}" IsChecked="{Binding RememberMe, Mode=TwoWay}" />
                                <TextBlock Grid.Column="1" HorizontalAlignment="Right"
                                           Visibility="{Binding CanChangePassword, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
                                    <Hyperlink Click="ChangePassword_Click">
                                        <TextBlock Text="{Binding ResourceKeyManager.SecurityControlResetPasswordButton}" />
                                    </Hyperlink>
                                </TextBlock>
                            </Grid>
                        </StackPanel>

                        <StackPanel Grid.Column="1" Visibility="{Binding CanShowIdentityProviders, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
                            <GroupBox Header="External Login" Margin="8">
                                <ItemsControl ItemsSource="{Binding LogOnDialogContext.IdentityProviders}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <WrapPanel Orientation="Vertical" />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Margin="5">
                                                <Button Content="{Binding Name}" Tag="{Binding Key}" MinWidth="100" Padding="4" Click="IdentityProvider_Click" />
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </GroupBox>
                        </StackPanel>
                        
                        <Grid Grid.Row="1" Grid.ColumnSpan="2" Background="#FFF0F0F0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlCloseButton}" Click="CloseDialog_Click" IsCancel="True" />
                            </StackPanel>
                            <StackPanel Grid.Column="3" Orientation="Horizontal" Margin="8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlShowProxyButton}" Click="ShowProxy_Click" 
                                        Visibility="{Binding CanShowProxySettings, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}" />
                            </StackPanel>
                            <StackPanel Grid.Column="4" Orientation="Horizontal" Margin="0,8,8,8">
                                <Button x:Name="LogOnButton" MinWidth="70" Padding="15,3,15,3" Margin="8,0,0,0" IsEnabled="{Binding CanLogOn, Mode=OneWay}" 
                                        Content="{Binding ResourceKeyManager.SecurityControlLogOnButton}" Click="LogOn_Click" />
                            </StackPanel>
                        </Grid>
                    </Grid>
                </TabItem>
                <TabItem Visibility="Collapsed">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel Margin="8">
                            <StackPanel>
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlSecurityCode}"/>
                                <TextBox x:Name="CodeBox" Grid.Column="1" Text="{Binding Code, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" Height="30" Padding="5,0" />
                            </StackPanel>
                        </StackPanel>
                        <Grid Grid.Row="1" Background="#FFF0F0F0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlCloseButton}" 
                                        Click="CloseDialog_Click" IsCancel="True" />
                            </StackPanel>
                            <StackPanel Grid.Column="4" Orientation="Horizontal" Margin="0,8,8,8">
                                <Button x:Name="SendCodeButton" MinWidth="70" Padding="15,3,15,3" Margin="8,0,0,0" IsEnabled="{Binding CanSendCode, Mode=OneWay}" 
                                        Content="{Binding ResourceKeyManager.SecurityControlSubmitButton}" Click="SendCodeButton_Click" />
                            </StackPanel>
                        </Grid>
                    </Grid>
                </TabItem>
                <TabItem Visibility="Collapsed">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel Margin="8">
                            <StackPanel>
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlResetPasswordUserName}"/>
                                <TextBox x:Name="EmailBox" Grid.Column="1" Text="{Binding Email, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" Height="30" />
                            </StackPanel>
                        </StackPanel>

                        <TextBox Grid.Row="1" Margin="8" TextWrapping="Wrap" IsReadOnly="True" BorderThickness="0"
                                    Text="{Binding ResourceKeyManager.SecurityControlResetPasswordHelpMessage, Mode=OneWay}" />

                        <Grid Grid.Row="2" Background="#FFF0F0F0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlCloseButton}" 
                                        Click="CloseDialog_Click" IsCancel="True" />
                            </StackPanel>
                            <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="0,8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlBackButton}" Click="GotoLogOn_Click" />
                            </StackPanel>
                            <StackPanel Grid.Column="4" Orientation="Horizontal" Margin="0,8,8,8">
                                <Button x:Name="SendEmailButton" MinWidth="70" Padding="15,3,15,3" Margin="8,0,0,0" IsEnabled="{Binding CanSendEmail}" 
                                        Content="{Binding ResourceKeyManager.SecurityControlSendEmailButton}" Click="SendEmail_Click" />
                            </StackPanel>
                        </Grid>
                    </Grid>
                </TabItem>
                <TabItem Visibility="Collapsed">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <TextBox Margin="8" TextWrapping="Wrap" IsReadOnly="True" BorderThickness="0"
                                    Text="{Binding ResourceKeyManager.SecurityControlResetPasswordMessage, Mode=OneWay}" />
                        <Grid Grid.Row="1" Background="#FFF0F0F0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlCloseButton}" 
                                        Click="CloseDialog_Click" IsCancel="True" />
                            </StackPanel>
                            <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="0,8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlBackButton}" Click="GotoLogOn_Click" />
                            </StackPanel>
                        </Grid>
                    </Grid>
                </TabItem>
                <TabItem Visibility="Collapsed">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel>
                            <StackPanel Margin="8">
                                <StackPanel>
                                    <TextBlock Text="{Binding ResourceKeyManager.SecurityControlNewPasswordSecurityCode}"/>
                                    <TextBox x:Name="NewPasswordCodeBox" Grid.Column="1" Text="{Binding NewPasswordCode, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" Height="30" Padding="5,0" />
                                </StackPanel>
                            </StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlNewPassword1}"/>
                                <PasswordBox x:Name="NewPasswordBox1" Grid.Column="1" VerticalContentAlignment="Center" Height="30" Padding="5,0" />
                            </StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlNewPassword2}"/>
                                <PasswordBox x:Name="NewPasswordBox2" Grid.Column="1" VerticalContentAlignment="Center" Height="30" Padding="5,0" />
                            </StackPanel>
                        </StackPanel>

                        <Grid Grid.Row="1" Background="#FFF0F0F0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlCloseButton}" 
                                        Click="CloseDialog_Click" IsCancel="True" />
                            </StackPanel>
                            <StackPanel Grid.Column="4" Orientation="Horizontal" Margin="0,8,8,8">
                                <Button x:Name="ChangePasswordButton" MinWidth="70" Padding="15,3,15,3" Margin="8,0,0,0" IsEnabled="{Binding CanResetPassword, Mode=OneWay}" 
                                        Content="{Binding ResourceKeyManager.SecurityControlSubmitButton}" Click="ResetPassword_Click" />
                            </StackPanel>
                        </Grid>
                    </Grid>
                </TabItem>
                <TabItem Visibility="Collapsed">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <StackPanel>
                            <StackPanel Margin="8">
                                <TextBlock Text="{Binding ResourceKeyManager.SecurityControlProxyAddress}"/>
                                <TextBox x:Name="ProxyAddressBox" Grid.Column="1" Text="{Binding Proxy.Address, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                         Height="30" Padding="5,0" />
                            </StackPanel>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>

                                <StackPanel Grid.Column="0" Margin="8">
                                    <TextBlock Text="{Binding ResourceKeyManager.SecurityControlProxyUserName}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Proxy.Credentials.UserName, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                         Height="30" Padding="5,0" />
                                </StackPanel>
                                <StackPanel Grid.Column="1" Margin="8">
                                    <TextBlock Text="{Binding ResourceKeyManager.SecurityControlProxyPassword}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Proxy.Credentials.Password, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                         Height="30" Padding="5,0" />
                                </StackPanel>
                                <StackPanel Grid.Column="2" Margin="8">
                                    <TextBlock Text="{Binding ResourceKeyManager.SecurityControlProxyDomain}"/>
                                    <TextBox Grid.Column="1" Text="{Binding Proxy.Credentials.Domain, UpdateSourceTrigger=PropertyChanged}" VerticalContentAlignment="Center" 
                                         Height="30" Padding="5,0" />
                                </StackPanel>
                            </Grid>
                        </StackPanel>
                        <Grid Grid.Row="1" Background="#FFF0F0F0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <StackPanel Grid.Column="0" Orientation="Horizontal" Margin="8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlCloseButton}" 
                                        Click="CloseDialog_Click" IsCancel="True" />
                            </StackPanel>
                            <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="0,8">
                                <Button MinWidth="70" Padding="15,3,15,3" Content="{Binding ResourceKeyManager.SecurityControlBackButton}" 
                                        Click="GotoLogOn_Click" />
                            </StackPanel>
                        </Grid>
                    </Grid>
                </TabItem>
                <TabItem Visibility="Collapsed">
                    <ContentControl x:Name="IdentityProviderControl" />
                </TabItem>
            </TabControl>
        </Grid>
    </Grid>
</UserControl>
